uniform sampler2D tex;
uniform samplerCube cube;

//light ambient, diffuse and specular colors
uniform vec4 lAmbient, lDiffuse, lSpecular;

// normal, light and view vectors in view space
varying vec3 nv, lv, vv;

// material ambient, diffuse and specular colors
const vec4 aColor = vec4(0.12, 0.11, 0.03, 1.);
const vec4 dColor = vec4(0.75, 0.60, 0.23, 1.);
const vec4 sColor = vec4(0.63, 0.55, 0.37, 1.);
const float shininess = 4.0;


void
main ()
{
    vec4 ambient_color = lAmbient * aColor;
    vec4 diffuse_color = vec4(0.0);
    vec4 specular_color = vec4(0.0);

    vec3 Nv = normalize(nv);
    vec3 Lv = normalize(lv);
    vec3 Vv = normalize(vv);

    float lambertTerm = dot(Nv,Lv);

    if(lambertTerm > 0.0)
    {

        diffuse_color = lDiffuse * dColor * lambertTerm;


        vec3 Rv = reflect(-Lv,Nv);

        float spec_factor = pow(max(dot(Rv,Vv), 0.0),
                                shininess );

        specular_color = lSpecular * sColor * spec_factor*textureCube(cube,reflect(-Vv, Nv));
    }
    vec4 color = texture2D(tex,gl_TexCoord[0].st);
    //vec4 color=textureCube(cube,reflect(-Vv, Nv));

    //if (color==vec4(0,0,0,0))
    //color==vec4(255,255,255,1);
     //   color+=gl_Color;
    //else color*=gl_Color;

    gl_FragColor = color+aColor + diffuse_color + specular_color;
}
